<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function User(name){
            this.name=name;
        }
        //在原型中添加show访问，被所有实例共享
        User.prototype.show=function(){
            //原型中方法的this依然指向实例对象
            console.log('大家好，我是：'+this.name);
        }

        var jack=new User("jack");
        var rose=new User("rose");

        console.log(jack.name===rose.name);  //false
        console.log(jack.show===rose.show);  //true

        jack.show();
        rose.show();

        //每个函数都包含prototype原型对象，原对象中的内容被所有实例共享
        console.dir(jack);
        console.log(jack.__proto__===rose.__proto__);  //true
        console.log(jack.__proto__===User.prototype);  //true

        console.dir(User);
        //在原型对象中拥有constructor属性指回构造器
        console.log(User.prototype.constructor===User);
        console.log(jack.__proto__.constructor===User);
    </script>
</body>
</html>